const ProjectModel = require('../../models/ProjectModel')

const ProductService = {
  add: async ({ title, introduction, detail, cover, updateTime }) => {
    return ProjectModel.create({ title, introduction, detail, cover, updateTime })
  },
  getList: async ({ id }) => {
    return id ? ProjectModel.find({ _id: id }) : ProjectModel.find({})
  },
  updateList: async ({ _id, title, introduction, detail, cover, updateTime }) => {
    if (cover) {
      return ProjectModel.updateOne({ _id }, { _id, title, introduction, detail, cover, updateTime })
    } else {
      return ProjectModel.updateOne({ _id }, { _id, title, introduction, detail, updateTime })
    }
  },
  deleteList: async (id) => {
    return ProjectModel.deleteOne({ _id: id },)
  }
}

module.exports = ProductService